﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BAL;
namespace QuanLyTiemNET_DEV_LINQ
{
    public partial class XtraFormThemKhachHang : DevExpress.XtraEditors.XtraForm
    {
        public XtraFormThemKhachHang()
        {
            InitializeComponent();
        }

        private void XtraFormThemKhachHang_Load(object sender, EventArgs e)
        {
            cmbMaLoaiKH.DataSource = BAL_LOAIKHACH.LayThpngTinLK();
            cmbMaLoaiKH.DisplayMember = "TenLoai";
            cmbMaLoaiKH.ValueMember = "MaLoaiKH";
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            txtMaKH.ResetText();
            txtHoTen.ResetText();
            txtSDT.ResetText();
            cmbMaLoaiKH.ResetText();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string err = null;
            try
            {
                if (DialogResult.Yes == MessageBox.Show("Bạn có chắc chắn muốn thêm khách hàng này???", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    if (BAL_KHACHHANG.ThemKH(ref err, txtMaKH.Text, txtHoTen.Text, txtSDT.Text, cmbMaLoaiKH.SelectedValue.ToString()))
                        MessageBox.Show("Thêm khách hàng " + txtHoTen.Text + " thành công!!!!");
                    else
                        MessageBox.Show("lỗi: " + err);
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }
        }

        private void txtMaKH_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                txtHoTen.Focus();
        }

        private void txtHoTen_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                txtSDT.Focus();
        }

        private void txtSDT_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                cmbMaLoaiKH.Focus();
        }
    }
}